﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Library;
using Library.DAO;
using Library.Entity;

namespace DesignLife.Admin.EditManager
{
    public partial class PortEdit : System.Web.UI.Page
    {
        private Portpolios por;
        private PortpoliosDAO pordao;
        public PortEdit()
        {
            por = new Portpolios();
            pordao = new PortpoliosDAO();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string temID = Request["portsId"];
                if (temID != null)
                {
                    por = pordao.GetPortById(int.Parse(temID));
                    txtid.Text = por.PortID.ToString();
                    txtname.Text = por.PortName;
                    txtlink.Text = por.Link;
                    txtPath.Text = por.Img;
                    }
            }

        }

        protected void btnsave_Click(object sender, EventArgs e)
        {
            HttpPostedFile file = Fuimage.PostedFile;

            try
            {
                string strPath = Server.MapPath("~/UploadFiles/" + Fuimage.FileName);
                Fuimage.SaveAs(strPath);
                txtPath.Text = "~/UploadFiles/" + Fuimage.FileName.ToString();
                lblSuccess.Text = "Add success full";

            }
            catch (Exception ex)
            {

                lblError.Text = "Upload is not valida!";
            }
        }

        protected void btnsubmit_Click(object sender, EventArgs e)
        {
            Portpolios por = new Portpolios();
            por.PortID = Utility.ToInt(txtid.Text);
            por.PortName = txtname.Text;
            por.Link = txtlink.Text;
            por.Img = txtPath.Text;
            pordao.Update(por);
            Response.Redirect("Admin/Port.aspx");
        }
    }
}